﻿<?php
$localpath = ".";
if(isset($_common['localpath']))
	$localpath = $_common['localpath'];
require_once($localpath.'/config.php'); 
require_once($localpath.'/include/class_com_sql.php'); // a mysql class.
class isa_book_post
{
    private $_name = "";
    private $_douban = "";
    private $_count = "";
    private $_status = "";
	private $_user = "";
	private $_url = "";
	
	function __construct($name, $douban, $count, $status, $user, $url)
	{
       $this->setName($name);
	   $this->setDouban($douban);
	   $this->setCount($count);
	   $this->setStatus($status);
	   $this->setUser($user);
	   $this->setUrl($url);
	}
	
	function __destruct()
	{
	}
	
	function Insert()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getInsert();
		$result = $db->query($sql);
		return $result;
	}
	
	function GetBooks()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getList();
		$result = $db->query($sql);
		return $result;
	}
	
	function GetBookById($id)
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getById();
		$result = $db->query($sql);
		return $result;
	}
	
	function GetBookByBouban()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getByBouban($this->_douban);
		$result = $db->query($sql);
		return $result;
	}
	
	function setName($name)
	{
		$this->_name = $this->Format($name);
	}
	
	function setDouban($douban)
	{
		$this->_douban = $this->Format($douban);
	}

	function setCount($count)
	{
		$this->_count = $this->Format($count);
	}

	function setStatus($status)
	{
		$this->_status = $this->Format($status);
	}

	function setUser($user)
	{
		$this->_user = $this->Format($user);
	}

	function setUrl($url)
	{
		$this->_url = $this->Format($url);
	}

	protected function Format($value)
	{
		$value = htmlspecialchars($value, ENT_QUOTES);
		$value = addslashes($value);
		return $value;
	}
	
	protected function getList()
	{
		$sql = "select * from `isa_web_book`";
		return $sql;
	}

	protected function getInsert()
	{
		$sql = "INSERT INTO  `sxisa`.`isa_web_book` (`book_name` ,`book_douban` ,`book_count` ,`book_status`,";
		$sql = $sql . "`book_user` ,`book_url` ,`book_date`) VALUES (";
		$sql = $sql . "'" . $this->_name . "', '" . $this->_douban . "', '" . $this->_count;
		$sql = $sql . "', '" . $this->_status . "', '" . $this->_user . "', '" . $this->_url ."', now())";
		return $sql;
	}

	protected function getbyId($id)
	{
		$sql = "select * from `isa_web_book` where `book_id` = '" . $id . "' limit 1";
		return $sql;
	}
	
	protected function getbyBouban($dbid)
	{
		$sql = "select * from `isa_web_book`  where `book_douban` = '" . $dbid . "' limit 1";
		return $sql;
	}

/*	protected function getRepeat($number, $email)
	{
		if($number != "")
			$sql = "select * from `isa_web_join`  where `join_number` = '" . $number . "' or `join_mail` = '" . $email . "' limit 1";
		else
			$sql = "select * from `isa_web_join`  where `join_mail` = '" . $email . "' limit 1";
		return $sql;
	}*/
}
?>